all: clean opt


############################################################
opt: parserx extlib-1.5/std.cmx
	ocamlopt -c -I extlib-1.5 sets.ml
	ocamlopt -c -I extlib-1.5 nba.ml
	ocamlopt -c -I extlib-1.5 graph.ml
	ocamlopt -c -I extlib-1.5 dfa.ml
	ocamlopt -c -I extlib-1.5 wdba.ml
	ocamlopt -c -I extlib-1.5 main.ml
	ocamlopt -o wdba -I extlib-1.5 bigarray.cmxa enum.cmx extString.cmx std.cmx lexer.cmx parser.cmx lexer2.cmx parser2.cmx sets.cmx nba.cmx graph.cmx dfa.cmx wdba.cmx main.cmx

extlib-1.5/std.cmx:
	$(MAKE) -C extlib-1.5 opt

parserx: lexer.cmx parser.cmx lexer2.cmx parser2.cmx

lexer.cmx parser.cmx:
	ocamllex -o lexer.ml lexer.mll             # generates lexer.ml
	ocamlyacc -b parser parser.mly             # generates parser.ml and parser.mli
	ocamlc -i syntax.ml > syntax.mli
	ocamlopt -c syntax.mli                        # -> Syntax.cmi
	ocamlopt -c syntax.ml                         # -> Syntax.cmx
	ocamlopt -c parser.mli
	ocamlopt -c lexer.ml
	ocamlopt -c parser.ml

lexer2.cmx parser2.cmx:
	ocamllex -o lexer2.ml lexer2.mll             # generates lexer2.ml
	ocamlyacc -b parser2 parser2.mly             # generates parser2.ml and parser2.mli
	ocamlc -i syntax.ml > syntax.mli
	ocamlopt -c syntax.mli                        # -> Syntax.cmi
	ocamlopt -c syntax.ml                         # -> Syntax.cmx
	ocamlopt -c parser2.mli
	ocamlopt -c lexer2.ml
	ocamlopt -c parser2.ml



############################################################
compile: parser extlib-1.5/std.cmo
	ocamlc -c -I extlib-1.5 sets.ml
	ocamlc -c -I extlib-1.5 nba.ml
	ocamlc -c -I extlib-1.5 graph.ml
	ocamlc -c -I extlib-1.5 dfa.ml
	ocamlc -c -I extlib-1.5 wdba.ml
	ocamlc -c -I extlib-1.5 main.ml
	ocamlc -o wdba -I extlib-1.5 bigarray.cma enum.cmo extString.cmo std.cmo lexer.cmo parser.cmo lexer2.cmo parser2.cmo sets.cmo nba.cmo graph.cmo dfa.cmo wdba.cmo main.cmo

profile: parser extlib-1.5/std.cmo
	ocamlcp -c -I extlib-1.5 sets.ml
	ocamlcp -c -I extlib-1.5 nba.ml
	ocamlcp -c -I extlib-1.5 graph.ml
	ocamlcp -c -I extlib-1.5 dfa.ml
	ocamlcp -c -I extlib-1.5 wdba.ml
	ocamlcp -c -I extlib-1.5 main.ml
	ocamlcp -o wdba bigarray.cma enum.cmo extString.cmo std.cmo lexer.cmo parser.cmo lexer2.cmo parser2.cmo sets.cmo nba.cmo graph.cmo dfa.cmo wdba.cmo main.cmo
	rm -f ocamlprof.dump

extlib-1.5/std.cmo:
	$(MAKE) -C extlib-1.5

parser: lexer.cmo parser.cmo lexer2.cmo parser2.cmo

lexer.cmo parser.cmo:
	ocamllex -o lexer.ml lexer.mll             # generates lexer.ml
	ocamlyacc -b parser parser.mly             # generates parser.ml and parser.mli
	ocamlc -i syntax.ml > syntax.mli
	ocamlc -c syntax.mli                        # -> Syntax.cmi
	ocamlc -c syntax.ml                         # -> Syntax.cmo
	ocamlc -c parser.mli
	ocamlc -c lexer.ml
	ocamlc -c parser.ml

lexer2.cmo parser2.cmo:
	ocamllex -o lexer2.ml lexer2.mll             # generates lexer2.ml
	ocamlyacc -b parser2 parser2.mly             # generates parser2.ml and parser2.mli
	rm -f syntax.mli
	cp syntax.ml syntax.mli
	ocamlc -c syntax.mli                        # -> Syntax.cmi
	ocamlc -c syntax.ml                         # -> Syntax.cmo
	ocamlc -c parser2.mli
	ocamlc -c lexer2.ml
	ocamlc -c parser2.ml



############################################################
doc:
	mkdir -p doc/
	ocamldoc -html -d doc/ -I extlib-1.5 *.ml

############################################################
clean:
	#$(MAKE) -C extlib-1.5 clean
	rm -f main
	rm -f *.cm[iox]
	rm -f *.*~
	rm -f *~
	rm -f *.o
	rm -f -r doc/
